<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>[2.21]-服务器统一部署方案简明版 | PhalApi(π框架) - PHP轻量级开源接口框架 - 助你创造价值！</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <meta content="email=no" name="format-detection">
    <meta name="Author" content="PhalApi,ecitlm,dogstar">
    <meta name="description" content="[2.21]-服务器统一部署方案简明版，PhalApi是一个PHP轻量级开源接口框架，致力于快速开发接口服务。支持HTTP/SOAP/RPC等协议，可用于搭建接口/微服务/RESTful接口/Web Services。我们不断更新，保持生气；为接口负责，为开源负责！并承诺永久免费！">
    <meta name="keywords" content="PhalApi,phalapi,phalapi接口开发,后台接口开发,后台接口开发框架,接口开发,接口框架,开源接口框架,PHP后台接口开发,PHP接口开发,PHP接口框架,PHP后台接口框架,phalapi官网,PHP接口框架,php接口开发框架,php接口开发,php web框架,π框架,π开发框架,π接口框架,π接口开发框架,api接口,php接口,,PHP接口框架,phalapi文档,phalapi wiki,PhalApi文档,phalapi在线文档,phalapi官方文档">

    <link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" media="screen">
    <link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.css" media="screen">
    <link rel="stylesheet" href="../css/main.css" />
    <link rel="stylesheet" href="../css/loading_bar.css" />
    <link rel="icon" href="http://webtools.qiniudn.com/dog_catch.png" type="image/x-icon" />
    <script src="../js/pace.min.js"></script>
	
	<!-- 代码高亮 -->
	<link rel="stylesheet" href="../css/highlight.min.css">
	<script src="../js/highlight.min.js"></script>
	<script>hljs.initHighlightingOnLoad();</script>
    
</head>

<body>
    <!-- navbar start -->
    <div class="navbar navbar-default navbar-fixed-top" id="mainnav" role="navigation">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand website_name" href="/"><!-- <span>PhalApi</span> --><strong></strong></a>
            </div>
            <div class="navbar-collapse collapse" aria-expanded="false" style="height: 1px;">
                <ul class="nav navbar-nav navbar-right" id="nav_bar">
                    <li><a href="https://www.phalapi.net/"><span class="glyphicon glyphicon-home"></span></a></li>
                    <li><a href="https://www.phalapi.net/download.html">下载</a></li>
                    <li class="active"><a href="https://www.phalapi.net/wikis/">文档</a></li>
                    <li><a href="https://www.phalapi.net/donate.html">贡献</a></li>
                    <li><a href="#">|</a></li>
                    <li><a href="http://qa.phalapi.net/" target="_blank">社区</a></li>
                    <li><a href="http://www.ituring.com.cn/book/2405" target="_blank">书籍</a></li>
                    <li><a href="http://demo.phalapi.net/listAllApis.php" target="_blank">体验</a></li>
                    <li><a href="https://github.com/phalapi/phalapi-library" target="_blank">扩展</a></li>
                </ul>
            </div>
            <!--/.nav-collapse -->
        </div>
    </div>
    <!-- navbar end -->


    <div id="content">
        <div class="container">
            <div class="row row-md-flex row-md-flex-wrap">
                <h4><a href="/wikis/%5B2.20%5D-%E7%BA%A6%E5%AE%9A%E7%BC%96%E7%A8%8B%EF%BC%9A%E6%9E%B6%E6%9E%84%E6%98%8E%E6%98%BE%E7%9A%84%E7%BC%96%E7%A8%8B%E9%A3%8E%E6%A0%BC.html">上一章</a>   <a href="/wikis/">文档首页</a>   <a href="/wikis/%5B2.22%5D-%E6%9B%B4%E5%A4%9A%E5%B7%A5%E5%85%B7%EF%BC%9A%E7%B2%BE%E7%9B%8A%E9%A1%B9%E7%9B%AE%E5%92%8C%E5%9B%A2%E9%98%9F%E5%BB%BA%E8%AE%BE.html">下一章</a></h4>
<hr />
<h2>2.21.1 前言</h2>
<p>目前服务器架构通常采用：CentOs + Nginx + php-fpm + MySql [+ Memcached]，现将部署方案安装方法、遇到的问题和解决方法、启动方式总结如下，以便后期服务器快速部署。  </p>
<pre><code>以下文档的是经过几个深夜整理并在阿里云服务器真实部署通过，运行良好，整个过程熟悉后约共半小时，可以进一步考虑做成自动化部署脚本。
如是，请把脚本也邮件发我一份。^_^</code></pre>
<h2>2.21.2 统一约定</h2>
<ul>
<li>全部使用编译安装</li>
<li>安装路径路径：/usr/local/</li>
<li>
<p>安装包存放位置：/home/apps/web/</p>
<p><strong>特别注意：请尽量不要使用root账号操作服务器，特别是对外服务器，谢谢。</strong>  </p>
</li>
</ul>
<h2>2.21.3 依赖库和开发工具</h2>
<pre><code class="language-bash">yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

# nginx
yum -y install pcre-devel zlib-devel

# php
yum -y install gd-devel libjpeg-devel libpng-devel freetype-devel libxml2-devel curl-devel freetype-devel

# mysql
yum -y install bison gcc gcc-c++ autoconf automake zlib* libxml* ncurses-devel libtool-ltdl-devel* mysql-devel

# sz rz
yum install lrzsz</code></pre>
<h2>2.21.4 安装Nginx 1.6.0</h2>
<h3>参考官方网站</h3>
<pre><code>http://wiki.nginx.org/Install</code></pre>
<h3>(1)安装</h3>
<pre><code class="language-bash">./configure --prefix=/usr/local/nginx
make
make install</code></pre>
<h3>(2)启动</h3>
<pre><code class="language-bash">/usr/local/nginx/sbin/nginx</code></pre>
<h3>(3)重启</h3>
<pre><code class="language-bash">/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload</code></pre>
<h3>(4)更多配置</h3>
<pre><code class="language-bash">server {
    listen 80;
    server_name test.wetime.com;
    root /home/apps/projects/test.wetime.com;
    charset utf-8;
    access_log logs/test.wetime.com.access.log;
    error_log logs/test.wetime.com.error.log;
    location / {
        index index.html index.htm index.php;
    }
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}</code></pre>
<h2>2.21.5 安装PHP-FPM 5.3.5</h2>
<h3>(1)参考</h3>
<pre><code>http://blog.csdn.net/dc_726/article/details/9519619</code></pre>
<h3>(2)安装</h3>
<pre><code class="language-bash">./configure --prefix=/usr/local/php --with-mcrypt --with-zlib --with-curl --with-gd --disable-debug --enable-fpm --enable-mbstring --enable-sockets --enable-zip --enable-xml --enable-pdo</code></pre>
<h4>温馨提示</h4>
<p>如果提示以下错误：</p>
<pre><code class="language-bash">If configure fails try --with-jpeg-dir=&lt;DIR&gt;
configure: error: libpng.(a|so) not found.</code></pre>
<p>则需要执行以下命令：</p>
<pre><code class="language-bash">cp  -frp /usr/lib64/libjpeg.* /usr/lib/
ln -s /usr/lib64/libpng.so /usr/lib/libpng.so

yum install libmcrypt libmcrypt-devel mcrypt mhash
yum install unixODBC-devel</code></pre>
<h3>(3)启动</h3>
<pre><code class="language-bash">/usr/local/php/sbin/php-fpm -y=/usr/local/php/etc/php-fpm.conf -c=/usr/local/php/etc/php.ini</code></pre>
<h3>(4)重启</h3>
<pre><code class="language-bash">/usr/local/php/sbin/php-fpm -y=/usr/local/php/etc/php-fpm.conf -c=/usr/local/php/etc/php.ini -t 
killall php
/usr/local/php/sbin/php-fpm -y=/usr/local/php/etc/php-fpm.conf -c=/usr/local/php/etc/php.ini</code></pre>
<h3>(5)错误处理与依赖</h3>
<pre><code class="language-bash">cp  -frp /usr/lib64/libjpeg.* /usr/lib/
ln -s /usr/lib64/libpng.so /usr/lib/libpng.so
yum install libmcrypt libmcrypt-devel mcrypt mhash
yum install unixODBC-devel

我们可以在命令下输入： 

yum localinstall –nogpgcheck http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum localinstall –nogpgcheck http://download1.rpmfusion.org/free/el/updates/6/x86_64/rpmfusion-free-release-6-1.noarch.rpm
yum localinstall –nogpgcheck http://download1.rpmfusion.org/nonfree/el/updates/6/x86_64/rpmfusion-nonfree-release-6-1.noarch.rpm

安装这3个东东后，我们就可以直接使用yum install libmcrypt来安装啦～</code></pre>
<h3>(6)php扩展安装</h3>
<pre><code class="language-bash">#安装mysql扩展
 ./configure --with-php-config=/usr/local/php/bin/php-config --with-mysql=/usr/local/mysql/
make
make install

#安装mysqli扩展
 ./configure --with-php-config=/usr/local/php/bin/php-config --with-mysqli=/usr/local/mysql/bin/mysql_config
make
make install</code></pre>
<p><em>扩展包位置在./php-5.3.5/ext/mysql，需要使用到 /usr/local/php/bin/phpize，扩展so应该放到：/usr/lib/php/modules/</em>  </p>
<p>此外，</p>
<pre><code>#PHP之pdo_mysql扩展安装步骤

# http://www.smallbigcake.com/2012/08/05/1572/ 
# http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz 

./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql 

如果提示“libmysqlclient.so.18: cannot open shared object file: No such file or directory in ”错误则参考 ：http://blog.itpub.net/26230597/viewspace-1161322/， 
或进行软链： 
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18 </code></pre>
<h2>2.21.6 安装MYSQL 5.6.10</h2>
<h3>(1)参考</h3>
<pre><code>http://www.cnblogs.com/xiongpq/p/3384681.html</code></pre>
<h3>(2)mysql-5.6.10.tar.gz下载</h3>
<pre><code>http://pan.baidu.com/share/link?shareid=3729862999&amp;uk=1327790029</code></pre>
<h3>(3)前期清理和依赖</h3>
<pre><code class="language-bash">rpm -e mysql   //普通删除模式
rpm -e --nodeps mysql    // 强力删除模式，如果使用上面命令删除时，提示有依赖的其它文件，则用该命令可以对其进行强力删除
yum -y install make gcc-c++ cmake bison-devel  ncurses-devel</code></pre>
<h3>(4)安装</h3>
<pre><code class="language-bash">cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci

make &amp;&amp; make install</code></pre>
<h3>(5)ERROR! The server quit without updating PID file</h3>
<pre><code class="language-bash">#去掉干扰的配置
mv /etc/my.cnf /etc/my.cnf.bak

#添加日记纪录
vim /usr/local/mysql/my.cnf
log-error=/var/log/mysqld.log
innodb_force_recovery=1</code></pre>
<h2>2.21.7 [可选]MEMCACHE 1.4.20</h2>
<h3>(1)参考官网</h3>
<pre><code>http://www.memcached.org/downloads</code></pre>
<h3>(2)更多参考</h3>
<pre><code>http://crtlib.blog.163.com/blog/static/133158013201392661912837/</code></pre>
<h3>(3)先安装依赖包</h3>
<pre><code class="language-bash">./configure --prefix=/usr/local/libevent/
make
make install</code></pre>
<h3>(4)安装</h3>
<pre><code class="language-bash">wget http://memcached.org/latest tar -zxvf memcached-1.x.x.tar.gz cd memcached-1.x.x ./configure &amp;&amp; make &amp;&amp; make test &amp;&amp; sudo make install</code></pre>
<h3>(5)最后成功安装后启动</h3>
<pre><code class="language-bash">/usr/local/memcached/bin/memcached -d -m 64 -u root -l 127.0.0.1 -p 11211 -c 128 -P /tmp/memcached.pid</code></pre>
<h3>(6)memcached 扩展</h3>
<pre><code class="language-bash">#http://blog.sina.com.cn/s/blog_66ac09390101drxc.html
#http://www.linuxidc.com/Linux/2013-07/87743.htm

#准备依赖包
./configure --prefix=/usr/local/libmemcached --with-memcached
make 
make install

#安装 扩展
/usr/local/php/bin/pecl install memcached
接着输入
libmemcached directory [no] : /usr/local/libmemcached</code></pre>
<hr />
<h4><a href="/wikis/%5B2.20%5D-%E7%BA%A6%E5%AE%9A%E7%BC%96%E7%A8%8B%EF%BC%9A%E6%9E%B6%E6%9E%84%E6%98%8E%E6%98%BE%E7%9A%84%E7%BC%96%E7%A8%8B%E9%A3%8E%E6%A0%BC.html">上一章</a>   <a href="/wikis/">文档首页</a>   <a href="/wikis/%5B2.22%5D-%E6%9B%B4%E5%A4%9A%E5%B7%A5%E5%85%B7%EF%BC%9A%E7%B2%BE%E7%9B%8A%E9%A1%B9%E7%9B%AE%E5%92%8C%E5%9B%A2%E9%98%9F%E5%BB%BA%E8%AE%BE.html">下一章</a></h4><div style="float: left">
<h4>
<a href="http://qa.phalapi.net/">还有疑问？欢迎到社区提问！</a>
&nbsp;&nbsp;
<a href="http://docs.phalapi.net/#/v2.0/">切换到PhalApi 2.x 开发文档。</a>
</h4>
</div>
            </div>
        </div>
    </div>

 <!-- 广告位 -->
<div class="grid-wrapper desktop-only">
	<p align="center">
		<a href="http://7xiz2f.com1.z0.glb.clouddn.com/%E6%88%91%E7%9A%84%E5%90%8D%E5%AD%97%E5%8F%AB%EF%BC%9A%CF%80%E6%A1%86%E6%9E%B6%20-%20PhalApi%202016%E5%B9%B4%E5%BA%A6%E5%BC%80%E6%BA%90%E6%80%BB%E7%BB%93%20-%20%E5%AE%98%E6%96%B9%E5%87%BA%E5%93%81.pdf" target="blank"><img width="950" height="100" src="http://7xiz2f.com1.z0.glb.clouddn.com/ad_20170104.png"></a>
		<a href="http://www.itran.cc/" target="blank"><img width="950" height="100" src="http://7xslqv.com1.z0.glb.clouddn.com/images/9/69/b88bc92455dc1239f9a5bf8d72929.png"></a>
		<a href="http://web-tools.phalapi.net/" target="blank"><img width="950" height="100" src="http://7xslqv.com1.z0.glb.clouddn.com/images/7/d0/88f523566c482296aecc43d185ca2.png"></a>
	</p>
</div>

        <!-- footer -->
        <div class="footer">
            <div class="link container ">
                <div class=" col-xs-7 col-sm-7 col-md-7 col-lg-7 ">
                    <h3>PhalApi (π框架)</h3>
                    <p>一个轻量级PHP开源接口框架，专注于接口服务开发，支持HTTP/SOAP/RPC协议，拥有自动生成的在线文档、多种开发语言的客户端SDK包以及可重用的扩展类库，可用于快速搭建微服务、RESTful接口或Web
                        Services。</p>
                    <!-- <p>:</p> -->
                    <a href="https://www.phalapi.net/" target="_blank"> PhalApi </a>
                    <span>|</span>
                    <a href="http://qa.phalapi.net/" target="_blank">社区</a>
                    <span>|</span>
                    <a href="download.html" target="_blank">下载</a>
                    <span>|</span>
                    <a href="/wikis/">文档</a>
                    <span>|</span>
                    <a href="http://www.ituring.com.cn/book/2405" target="_blank">书籍</a>
                    <span>|</span>
                    <a href="http://demo.phalapi.net/listAllApis.php" target="_blank">体验</a>
                    <span>|</span>
                    <a href="donate.html" target="_blank">贡献</a>
                    <span>|</span>
                    <a href="https://github.com/phalapi/phalapi-library" target="_blank">扩展</a>
                    <span>|</span>
                    <a href="/license.html" target="_blank">许可</a>
                    <span>|</span>
                    <a href="/about.html" target="_blank">关于</a>
                    <span>|</span>
                    <a href="https://www.phalapi.net/wikis/en/" target="_blank">English</a>

                </div>
                <div class=" col-xs-5 col-sm-5 col-md-5 col-lg-5 contact_us ">
                    <h3>联系我们</h3>
                    <a href="https://github.com/phalapi/phalapi"><img src="../images/github.png" alt="github" /></a>
                    <a href="http://weibo.com/p/100808d236e99beb645bfb56ed1c37dde9b8bd?k=phalapi%E5%BC%80%E6%BA%90%E6%A1%86%E6%9E%B6&from=501&_from_=huati_topic"><img src="../images/weibo.png"  alt="weibo" /></a>
                    <a href="http://7xslqv.com1.z0.glb.clouddn.com/images/1/b0/894fde762850cb11250253f7d5ede.png"><img src="../images/zfb.png"  alt="zfb" /></a>
					<a target="_blank" href="//shang.qq.com/wpa/qunwpa?idkey=f16292029e59975d4ccfccc70ed87aa5c5646df512e83b0e9e1270e8368be461"><img border="0" src="images/qq.png" alt="π框架 - PhalApi交流群②" title="π框架 - PhalApi交流群②"></a>
					<a href="http://git.oschina.net/dogstar/PhalApi"><img src="../images/git-oschina.png"  alt="git-oschina" /></a>
                </div>
                <div class="cls"></div>
                <div class="text-center copy_right"> ©2015-2017 PhalApi All Rights Reserved. <a href="http://www.miitbeian.gov.cn" target="_blank">粤ICP备15028808号</a>

				<script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_1255326144'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s4.cnzz.com/z_stat.php%3Fid%3D1255326144%26show%3Dpic' type='text/javascript'%3E%3C/script%3E"));</script>
                </div>
            </div>
        </div>
    </div>


    <a href="https://github.com/phalapi"><img id="gitHub_fllow" style="position: fixed; top: 0; right: 0; border: 0;z-index:9999" src="https://camo.githubusercontent.com/652c5b9acfaddf3a9c326fa6bde407b87f7be0f4/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6f72616e67655f6666373630302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png"></a>


    <script src="../js/jquery-1.11.1.min.js"></script>
    <script src="../js/bootstrap.min.js"></script>
</body>

</html>